#include <iostream>
using namespace std;

bool fibon_elem(int, long long &);

int main()
{
    int pos;
    cout << "Please enter a position: ";
    cin >> pos;

    long long elem;
    if (fibon_elem(pos, elem))
        cout << "elemnt # " << pos
             << " is " << elem << endl;
    else
    {
        cout << "Sorry. Could not calculate # "
             << pos << endl;
    }

    return 0;
}

bool fibon_elem(int pos, long long &elem)
{
    if (pos <= 0 || pos > 1024)
        {
            elem = 0;
            return false;
        }
    elem = 1;
    long long n_2 = 1, n_1 = 1;

    for (int ix = 3; ix < pos; ix++)
    {
        elem = n_1 + n_2;
        n_2 = n_1;
        n_1 = elem;
    }

    return true;
}